package login;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

/**
 * 负责人：罗登明
 * 将相对应的方法填入case下面
 *
 */
public class LoginView {
    public User viewLogin() {
        Login login = new Login();//****创建登入对象，放在循环外,因为登入和注册都需要使用
        int choice =-1;
        String username = null;
        father:while(true) {
            System.out.println("-------图书管理系统-------");//为了好看
            System.out.println("1.普通用户");
            System.out.println("2.管理员");
            System.out.println("0.退出");
            System.out.println("请选择你的身份：");
            Scanner scanner = new Scanner(System.in);
            while(true) {
                if (scanner.hasNextInt()) {
                    choice = scanner.nextInt();
                    break;
                } else {
                    System.out.println("非法输入,请重新输入:");
                    scanner.next();
                }
            }
            if(choice ==0) {
                System.out.println("感谢使用!!!");
                System.exit(0);
            }
            child:while(true) {
                if(choice==1) {
                    System.out.println("--------用户登入\\注册--------");//为了好看
                     }
                else {
                    System.out.println("--------管理员登入--------");
                }
                System.out.println("1.登录");
                if(choice==1)
                {
                    System.out.println("2.注册");
                    System.out.println("3.忘记密码");
                }
                System.out.println("0.返回");
                System.out.println("请输入你的选择：");
                int choice1 = -1;
                while(true) {
                    if (scanner.hasNextInt()) {
                        choice1 = scanner.nextInt();
                        break;
                    } else {
                        System.out.println("非法输入,请重新输入:");
                        scanner.next();
                    }
                }
                switch (choice1) {
                    case 1:
                        username = login.login();
                        break father;
                    case 2:
                        SignUp sign = new SignUp();
                        sign.signUp();
                        break;
                    case 3:
                        GetBack getBack = new GetBack();
                        getBack.getBack();
                        break;
                    case 0:break child;//利用标签结束内循环
                }
            }
        }

        if(choice == 2)
        {
            return new AdminUser(username);
        }
        else{
            return new NormalUser(username);
        }
    }
}
